package com.example.iwouldfindyou;

import android.app.Activity;
import android.app.Activity;
import android.content.Context;
import android.location.GpsStatus;
import android.location.GpsStatus.Listener;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class IwantLocation extends Activity{
	
	private LocationManager lm;
    TextView latitude =  (TextView) findViewById(R.id.textView2);
	TextView longitude =  (TextView) findViewById(R.id.textView3);
	
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.activity_main);
	        
			
			lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
			
			if ( lm.isProviderEnabled(LocationManager.GPS_PROVIDER) ) {
				 
				startGps();
 
            }else{
                //se vi sono errori
            }
			
			        
	 }
	 
	 public void startGps(){
			
         lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 , 5, new LocationListener(){ 
		  
	 
		@Override
		public void onLocationChanged(android.location.Location location) {
			
			latitude.setText("Latitude is  " + String.valueOf(location.getLatitude()));
			longitude.setText("Longitude is  " + String.valueOf(location.getLongitude()));
			
		}

		@Override
		public void onStatusChanged(String provider, int status, Bundle extras) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onProviderEnabled(String provider) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onProviderDisabled(String provider) {
			// TODO Auto-generated method stub
			
		}
		 
	 });
	 }

}
